<?php
namespace app\index\controller;

use app\BaseController;
use think\facade\View;
use think\facade\Request;
use think\captcha\facade\Captcha;

class Front extends BaseController
{
    protected $data = [];
    protected $response = [];
    protected $code = 1;
    protected $msg = 'ok';
    // 初始化
    protected function initialize()
    {
        $this->data = Request::param();
        View::assign('entrance',strtolower(Request::controller()));
        View::assign('action',strtolower(Request::action()));
    }
    protected function fetch($tmp=null)
    {
        $this->response['code'] = $this->code;
        $this->response['msg'] = $this->msg;
        //自动处理返回数据格式
        if(Request::isAjax()){
            return $this->response;
            return json($this->response);
        }
        View::assign($this->response);
        if($tmp)
        {
            return View::fetch($tmp);
        }else{
            return View::fetch();
        }
    }
    protected function assign($name,$value=null)
    {
        if(is_array($name)){
            $this->response = array_merge($this->response,$name);
        }
        if(is_string($name)){
            $this->response[$name] = $value;
        }
    }
    protected function setmodel()
    {

    }
}
